package com.zjsru.dailytest;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: likew
 * @Date: 2022/2/22
 *
 * 杨辉三角形2
 *
 * 写出所在行数的三角形数组
 */
public class getRow {
    public List<Integer> getRow(int rowIndex) {
        List<List<Integer>> ret = new ArrayList<List<Integer>>();
        for (int i = 0; i <= rowIndex ; i++) {
            List<Integer> row = new ArrayList<Integer>();
            for (int j = 0; j <= i; j++) {
                if(j == 0 || j == i){
                    row.add(1);
                }else {
                    row.add(ret.get(i - 1).get(j - 1) + ret.get(i - 1).get(j));
                }
            }
            ret.add(row);
        }
        return ret.get(rowIndex);
    }

    public static void main(String[] args) {
        getRow getRow = new getRow();
        int rowIndex = 5;
        System.out.println(getRow.getRow(rowIndex));
    }
}
